/*
 * @lc app=leetcode.cn id=83 lang=java
 *
 * [83] 删除排序链表中的重复元素
 */

// @lc code=start
/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
class Solution {
    /**
     * Accepted
    166/166 cases passed (0 ms)
    Your runtime beats 100 % of java submissions
    Your memory usage beats 77.13 % of java submissions (40.9 MB)
     */
    public ListNode deleteDuplicates(ListNode head) {
        ListNode l = head;
        while (l != null) {
            while (l.next != null && l.val == l.next.val) {
                l.next = l.next.next;
            }
            l = l.next;
        }
        return head;
    }
}
// @lc code=end
